package com.banmao.algorithm.No401To500.No559;

import java.util.ArrayDeque;
import java.util.List;

public class Solution1 {

    int depth = 0;

    public int maxDepth(Node root) {

        ArrayDeque<Node> queue = new ArrayDeque<>();
        if(root == null) {
            return depth;
        }
        queue.add(root);
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                Node poll = queue.poll();
                if(poll.children.size() > 0) {
                    queue.addAll(poll.children);
                }
            }
            if(size > 0) {
                depth++;
            }
        }
        return depth;
    }

}

class Node {
    public int val;
    public List<Node> children;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
}
